package com.example.shushiyunsst.fragment.main.home.child.miner.sub

import android.os.Bundle
import android.view.View
import com.example.library_common.adapter.JssBaseViewHolder
import com.example.library_common.album.utils.Utils
import com.example.library_common.base.SimpleListFragment
import com.example.library_common.bean.CommonBean
import com.example.shushiyunsst.R
import com.example.shushiyunsst.fragment.main.home.child.miner.bean.StartTransferBuyingSubBean
import com.lxj.xpopup.XPopup
import ikidou.reflect.TypeBuilder
import java.lang.reflect.Type


/**
 * 星树交易(买-子页面)
 * */
class StartTransferBuyingSubFragment(override val title: String) :
    SimpleListFragment<StartTransferBuyingSubBean>(), StartTransferBuyingLab {

    companion object {
        fun newInstance(title: String): StartTransferBuyingSubFragment {
            val args = Bundle()
            val fragment = StartTransferBuyingSubFragment(title)
            fragment.arguments = args
            return fragment
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        isEnableLoadMore = false
        isAddDividerItemDecoration = false
        mSuperBackPressedSupport=false

    }

    override fun initView(view: View) {
        super.initView(view)
        mAdapter.addChildClickViewIds(R.id.buying_on)
        mAdapter.setOnItemChildClickListener { adapter, view, position ->
            XPopup.Builder(_mActivity)
                .hasShadowBg(false)
                .asCustom(StartTransferBuyingSubPop(_mActivity))
                .show()
        }
    }

    override fun getItemLayout() = R.layout.start_transfer_buying_sub_fragment

    override fun convertItem(helper: JssBaseViewHolder?, item: StartTransferBuyingSubBean?) {
        val flags = helper?.layoutPosition == 0
        val tex = if (flags) "平台恒定发行   777棵" else "会员昵称 （123**456）"
        helper
            ?.setText(R.id.title_template, tex)
            ?.setViewSelect(R.id.rect_frame, flags)
            ?.setViewSelect(R.id.single_price_Tv, flags)
            ?.setViewSelect(R.id.single_price_value_Tv, flags)
            ?.setViewSelect(R.id.buying_on, flags)
    }

    override fun getListType(): Type {
        return TypeBuilder.newInstance(CommonBean::class.java)
            .beginSubType(List::class.java)
            .addTypeParam(StartTransferBuyingSubBean::class.java).endSubType().build()
    }

    override fun netRequest() {
        val jsonFromRaw = Utils.getJsonFromRaw(_mActivity, R.raw.temp_fack_data)
        parseDate(jsonFromRaw)
    }
}